package cn.yitun.chat.yitunchatnettysdk.netty.tcp;

import cn.yitun.chat.yitunchatbasesdk.server.im.dispatcher.handler.SessionHandler;
import cn.yitun.chat.yitunchatbasesdk.server.im.dispatcher.handler.SessionMessageHandler;
import cn.yitun.chat.yitunchatnettysdk.netty.common.coder.StringServerCodec;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;

/**
 * 
 * Description <br>
 * Date 2019-07-21 18:38:42<br>
 * @author yitun
 * @since 1.1
 */
public class SocketServerInitializer extends ChannelInitializer<SocketChannel> {

	private SessionMessageHandler messageHandler;
	private SessionHandler sessionHandler;

	public SocketServerInitializer(SessionMessageHandler messageHandler, SessionHandler sessionHandler) {
		this.messageHandler = messageHandler;
		this.sessionHandler = sessionHandler;
	}

	@Override
	public void initChannel(SocketChannel sh) throws Exception {
		ChannelPipeline pipeline = sh.pipeline();
		pipeline.addLast("coder", new StringServerCodec());
		pipeline.addLast("handler", new SocketHandler(messageHandler, sessionHandler));
	}
}
